package com.atguigu.gmall.realtime.utils;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * Author: Felix
 * Date: 2022/1/22
 * Desc: 获取线程池工具类
 */
public class ThreadPoolUtil {

    private static ThreadPoolExecutor pool;

    //获取线程池
    public static ThreadPoolExecutor getInstance(){
        if(pool == null){
            synchronized(ThreadPoolUtil.class){
                if(pool == null){
                    System.out.println("----开辟线程池----");
                    pool = new ThreadPoolExecutor(
                        4,20,300, TimeUnit.SECONDS,
                        new LinkedBlockingDeque<Runnable>(Integer.MAX_VALUE));
                }
            }
        }

        return pool;
    }
}
